package com.study.jyg.rxjava2study.activity.txplayer;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.study.jyg.rxjava2study.R;
import com.study.jyg.rxjava2study.base.BasicActivity;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;

public class PlayerActivity extends BasicActivity {

    private final String TEST_URL = "http://200024424.vod.myqcloud.com/200024424_709ae516bdf811e6ad39991f76a4df69.f20.mp4";
    private String[] urls = {TEST_URL, TEST_URL, TEST_URL, TEST_URL, TEST_URL, TEST_URL};

    private RecyclerView recyclerView;
    private ListPlayerAdapter adapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_player;
    }

    @Override
    protected void initView() {
        recyclerView = findViewById(R.id.recyclerView);
        initAdapter();
    }

    private void initAdapter() {
        adapter = new ListPlayerAdapter(mContext, new ArrayList<>(Arrays.asList(urls)));
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(adapter);
        new PagerSnapHelper().attachToRecyclerView(recyclerView);

        try {
            Class clz = Class.forName("androidx.recyclerview.widget.RecyclerView");
            Constructor rcConstructor = clz.getConstructor();
            Object rcView = rcConstructor.newInstance();
            Method cancelTouch = clz.getMethod("cancelTouch");
            cancelTouch.setAccessible(true);
            cancelTouch.invoke(rcView);
        } catch (ClassNotFoundException | NoSuchMethodException
                | IllegalAccessException | InstantiationException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    public interface LifecycleListener{
        void onStart();
        void onCreate();
        void onResume();
        void onPause();
        void onStop();
        void onDestroy();
    }

}